//
//  XGDatePicker.m
//  DreamOf
//
//  Created by 薛小刚 on 2018/8/13.
//  Copyright © 2018年 薛小刚. All rights reserved.
//

#import "XGDatePicker.h"

@interface XGDatePicker()<PGDatePickerDelegate>

@property (nonatomic, assign) PGDatePickerMode type;

@end

@implementation XGDatePicker

- (instancetype)initWithType:(PGDatePickerMode)type {
    if (self = [super init]) {
        self.type = type;
    }
    return self;
}

- (void)showWithController:(UIViewController *) controller Date:(void(^)(NSString * date)) dateString {
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.cancelButtonText = @"取消";
    datePickManager.cancelButtonTextColor = [UIColor whiteColor];
    datePickManager.confirmButtonText = @"确定";
    datePickManager.confirmButtonTextColor = [UIColor whiteColor];
    datePickManager.headerViewBackgroundColor = [UIColor blackColor];
    
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.middleTextColor = [UIColor color_text_white];
    datePicker.backgroundColor = [UIColor color_main_background_color];
    datePicker.datePickerMode = self.type;
    [controller presentViewController:datePickManager animated:false completion:nil];
    datePicker.selectedDate = ^(NSDateComponents *dateComponents) {
        NSString * string;
        if (self.type == PGDatePickerModeYear) {
            string = [NSString stringWithFormat:@"%lu", dateComponents.year];
        } else if (self.type == PGDatePickerModeDate) {
            string = [NSString stringWithFormat:@"%lu-%lu-%lu", dateComponents.year, dateComponents.month, dateComponents.day];
        } else if (self.type == PGDatePickerModeDateHourMinute) {
            string = [NSString stringWithFormat:@"%lu-%lu-%lu %lu:%lu", dateComponents.year, dateComponents.month, dateComponents.day, dateComponents.hour, dateComponents.minute];
        }
        dateString(string);
    };
}


@end
